In [5]:
def re_read(in_n):
out_n = ""
p = in_n[0]
c_p = 1
for n in in_n[1:]:
if n != p:
out_n += "{}{}".format(c_p, p)
p = n
c_p = 1
else:
c_p += 1
if in_n[-1] == p:
out_n += "{}{}".format(c_p, p)
return out_n
In [8]:
# Example
token = "1"
print(token)
for i in range(5):
token = re_read(token)
print(token)
In [12]:
%%time
# Input
token = "1113122113"
for i in range(40):
token = re_read(token)
print(len(token))
In [13]:
%%time
# Input
token = "1113122113"
for i in range(50):
token = re_read(token)
print(len(token))
In [ ]: